/**
 * 
 */
package com.lunevich.json.tasks;

import java.util.List;

import android.os.AsyncTask;

/**
 * @author Andrei_Lunevich
 *
 */
public abstract class CommonAsyncTask<T> extends AsyncTask<String, Void, List<T>> {
	
	private Exception exception;
	private String url;

	@Override
	protected List<T> doInBackground(String... params) {
		url = params[0];
		exception = null;
		try {
			return onLoad(url);
		} catch (Exception e) {
			exception = e;
		}
		return null;
	}
	
	@Override
	protected void onPostExecute(List<T> twitterList) {
		if (exception != null) {
			onLoadError(exception);
		} else {
			onLoadSuccess(twitterList);
		}
	}
	
	public abstract List<T> onLoad(String url) throws Exception;
	
	public abstract void onLoadSuccess(List<T> contactList);
	
	public abstract void onLoadError(Exception exception);
}